<template>
  <div>

    <div class="header">
      <div class="left">
        <el-row>
          <el-button
            type="success"
            class="el-icon-circle-plus-outline"
            @click="add"
            >新增</el-button
          >
          <el-button
            type="success"
            class="el-icon-circle-close"
            @click="Myexport"
            >导出</el-button
          >
        </el-row>
      </div>
      <div class="right">
        <el-input v-model="input" placeholder="查找" class="myinput"  ></el-input>
        <el-button class="el-icon-search sou" @click="select"></el-button>
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="url">
        <template slot-scope="scope">
        <img src="http://192.168.1.137:8080//uploadFile/2022-05-10/b394dd8319f84ecab27b86e3c0f99012.jpg"></img>
        </template></el-table-column>
      <el-table-column prop="drug_class_name" label="药品分类">
      </el-table-column>
      <el-table-column prop="drug_name" label="药品名称"> </el-table-column>

      <el-table-column prop="serial_number" label="药品编号"> </el-table-column>
      <el-table-column prop="model" label="型号"> </el-table-column>
      <el-table-column prop="unit_price" label="客户单价"> </el-table-column>
      <el-table-column prop="inventory" label="库存数量"> </el-table-column>
      <el-table-column prop="unit" label="单位"> </el-table-column>
      <el-table-column prop="employee_real_name" label="负责人">
      </el-table-column>
      <el-table-column prop="supplier_name" label="供应商"> </el-table-column>
      <el-table-column prop="create_time" label="创建时间"> </el-table-column>
      <el-table-column prop="status_value" label="状态">
        <template slot-scope="scope"
          ><el-tag v-if="scope.row.status_value == '有效'" type="success"
            >有效</el-tag
          >
          <el-tag type="info" v-else-if="scope.row.status_value == '无效'"
            >无效</el-tag
          ></template
        >
      </el-table-column>
      <el-table-column label="操作" class="roeone" width="300">
        <template slot-scope="scope">
          <el-button
            type="primary"
            class="el-icon-edit modbt"
            @click="mod(scope.row)"
            >修改</el-button
          >
          <el-button
            type="danger"
            class="el-icon-close modbt"
            @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <page :countNum="countNum" @changePage="changePage"></page>
  </div>
</template>
<script>
import { home, del, Myexport } from "../../utils/api/Drug";
import page from "../../components/report_ssh/pageFtoor.vue";
export default {
  name: "diagnPage",
  created() {
    this.home();
  },
  methods: {
    select() {
      this.all.search = this.input;
      this.home();
      // console.log(this.all.search);
    },
    changePage(page) {
      this.all.index = page;
      this.home();
    },
    Myexport() {
      Myexport().then((data) => {
        this.download(data.data);
        // console.log(data);
      });
    },
    // 将后台返回的乱码解析成文件下载
    download(data) {
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", "药品管理报表.xlsx");

      document.body.appendChild(link);
      link.click();
    },

    mod(row) {
      // console.log(row);
      this.$router.push({
        path: "/home/Drug_administration/Drug_mod",
        query: { ...row },
      });
    },
    add() {
      this.$router.push("/home/Drug_administration/Drug_add");
    },
    home() {
      home(this.all).then((data) => {
        this.tableData = data.data.data.drugMngVos;
        // console.log(this.tableData);
        this.countNum = data.data.data.allCount;
        // console.log(this.countNum);
      });
    },
    del(id) {
      del(id).then((data) => {
        this.home();
      });
      this.$message({
        message: "您已成功删除",
        type: "success",
      });
    },
  },
  components: {
    page,
  },
  data() {
    return {
      input: "",
      dialogTableVisible: false,
      tableData: [],
      all: {
        index: "1",
        pageSize: "20",
        search: null,
      },
      countNum: 0,
    };
  },
};
</script>
<style lang="less" scoped>
.top {
  padding: 10px;
  font-size: 18px;
  box-sizing: border-box;
}
.header {
  button {
    line-height: 5px;
    font-weight: bold;
    margin: 10px 6px;
  }
}
.left {
  float: left;
}
.right {
  float: right;
  button {
    height: 40px;
    margin: 0;
  }
  .myinput {
    width: 200px;
    height: 30px;
  }
}
.modbt {
  width: 70px;
  // height: 26px;
  line-height: 10px;
  font-weight: bold;
}
.block {
  text-align: center;
  margin-top: 10px;
}
.see {
  border: 1px solid black;
  border-collapse: collapse;
  tr {
    border: 1px solid black;
    td {
      border: 1px solid black;
    }
  }
}
</style>